home *** CD-ROM | disk | FTP | other *** search
/ MacWorld UK 2000 March / MW_UK_2000_03.iso / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / scilabMode.tcl < prev    next >
Encoding:
Text File  |  1999-07-11  |  5.9 KB  |  193 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*- (install)
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "scilabMode.tcl"
  6.  #                                    created: 15/4/97 {4:03:22 pm} 
  7.  #                                last update: 24/2/1999 {9:38:59 pm} 
  8.  #  Author: Vince Darley
  9.  #  E-mail: <vince@santafe.edu>
  10.  #    mail: 317 Paseo de Peralta, Santa Fe, NM 87501, USA
  11.  #     www: <http://www.santafe.edu/~vince/>
  12.  #  
  13.  #  Mode for 'Scilab'
  14.  #  
  15.  # Installation:
  16.  # 
  17.  #  Requires Alpha version 7.0 or newer.  Just drop this file into
  18.  #  the Alpha:Tcl:Modes: folder, rebuild your Tcl indices (using
  19.  #  the Tcl menu which will be there when you read this file in Alpha)
  20.  #  then quit and restart Alpha.  Now any file ending in '.sci' 
  21.  #  automatically opens in Scilab mode.  You also need to paste the
  22.  #  included icon from 'newMenuIcons.rsrc' into Alpha.  If for some
  23.  #  reason you got this file without that rsrc file, then add the line
  24.  #  'set scilabMenu "Scil"' to your prefs.tcl file.  Note: the more
  25.  #  useful features of this mode are only available if you've
  26.  #  installed "Vince's Additions".
  27.  #  
  28.  #  We can't do too much exciting, since Scilab only handles an
  29.  #  'open' apple-event --- therefore it's not usefully scriptable.
  30.  #  
  31.  # Features:
  32.  # 
  33.  #  Automatically scans Scilab's 'Help' directory to pick up all
  34.  #  Scilab keywords so they can be coloured.
  35.  #  
  36.  #  Command-clicking on a keyword opens up a window with the help
  37.  #  information for that keyword (optionally this can be made to
  38.  #  open in Scilab itself)
  39.  #  
  40.  # If Vince's Additions is installed, the following features are
  41.  # also available:
  42.  # 
  43.  #  Keywords can be completed (enter the first few letters 
  44.  #  followed by 'cmd-tab')
  45.  #  
  46.  #  Function calls can be extended to list their arguments,
  47.  #  with template stops at each argument (again use cmd-tab).
  48.  #  
  49.  #  e.g. type 'sysl<cmd-tab>' and it is completed to 'syslin'
  50.  #  and immediately expanded to:
  51.  #      syslin(•<dom>,•<A>,•<B>,•<C >•<[,D [,x0] ]>)•
  52.  #  pressing tab moves from one argument to the next, highlighting
  53.  #  each argument in turn for each entry.
  54.  #  
  55.  # This file is copyright Vince Darley 1997, but freely distributable
  56.  # provided you note any modifications you make below.
  57.  # ###################################################################
  58.  ##
  59.  
  60. alpha::mode Scil 1.0 scilabMenu {*.sci *.dem} scilabMenu {
  61.     addMenu scilabMenu "•283"
  62. }
  63.  
  64. newPref f alphaOpensHelpFiles 1 Scil
  65. newPref v wordBreak {[\w_]+} Scil
  66. newPref v wordBreakPreface {[^_\w]} Scil
  67. newPref v stringColor green Scil
  68. newPref v commentColor red Scil
  69. newPref v keywordColor blue Scil
  70.  
  71. proc scilabMenu {} {}
  72.  
  73. Menu -n $scilabMenu -p Scil::menuProc {
  74.     "/S<U<OswitchToScilab"
  75.     "(-"
  76.     "/K<U<OopenFileInScilab"
  77.     "/K<U<O<BswitchFileToScilab"
  78.     "/C<O<UsetClipboardToExecFile"
  79.     "rebuildScilabKeywords"
  80. }
  81.  
  82.  
  83. proc Scil::menuProc {menu item} {
  84.     switch -- $item {
  85.     switchToScilab {app::launchFore SLab}
  86.     openFileInScilab {
  87.         openAndSendFile SLab
  88.     }
  89.     switchFileToScilab {
  90.         openAndSendFile SLab
  91.         killWindow
  92.     }
  93.     setClipboardToExecFile {
  94.         putScrap "exec('[win::CurrentTail]')"
  95.     }
  96.     rebuildScilabKeywords {Scil::RebuildElectrics}
  97.     }
  98. }
  99.  
  100. set completions(Scil) \
  101.   {completion::cmd completion::electric completion::word}
  102.  
  103. proc Scil::RebuildElectrics {} {
  104.     # Get keywords by looking for all help documents,
  105.     # simple but effective.  There may be a better way.
  106.     global Scilcmds PREFS Scilelectrics
  107.     set p [pwd]
  108.     set dir  [file join [file dirname [nameFromAppl SLab]] man]
  109.     cd $dir
  110.     regsub -all ".hlp" [glob *.hlp] "" Scilcmds
  111.     cd $p
  112.     set Scilcmds " ${Scilcmds} "
  113.     set fout [open [file join ${PREFS} ScilData] w]
  114.     puts $fout "set Scilcmds \{${Scilcmds}\}"
  115.     foreach f $Scilcmds {
  116.     message "scanning $f…"
  117.     set fileid [open [file join ${dir} ${f}.hlp] r]
  118.     set contents [read $fileid]
  119.     close $fileid
  120.     if [regexp "NAME\[ \r\n\t\]+${f} - (\[^\r\n\]*)\[ \r\n\t\]+CALLING SEQUENCE\[ \r\n\t\]+(${f}|\[^=\]+= *${f})(\(\[^\r\n\]+)\)\[ \r\n\t]" \
  121.       $contents "" desc "" arg] {
  122.         if [regexp  {\((.*)\)(.*)} $arg "" in after] {
  123.         if [regexp {(, *)?\[.*\]} $in brace] {
  124.             regsub {(, *)?\[.*\]} $in {◊} in
  125.             regsub -all {,} $in {•,•} in
  126.             if {$in != "◊"} {
  127.             regsub {◊} $in "••${brace}•" in
  128.             set in "(•${in})$after"
  129.             } else {
  130.             regsub {◊} $in "•${brace}•" in
  131.             set in "(${in})$after"
  132.             }
  133.         } else {
  134.             regsub -all {,} $in {•,•} in
  135.             if {$in != ""} {
  136.             set in "(•${in}•)$after"
  137.             } else {
  138.             set in "()$after"
  139.             }
  140.         }
  141.         set Scilelectrics($f) "${in}•$desc•"                
  142.         } else {
  143.         set Scilelectrics($f) "${arg}•$desc•"
  144.         }
  145.         puts $fout "set Scilelectrics($f) \{$Scilelectrics($f)\}"
  146.     }
  147.     }
  148.     close $fout
  149.     message "done"
  150.     
  151. }
  152.  
  153. ## 
  154.  # -------------------------------------------------------------------------
  155.  # 
  156.  # "Scil::DblClick" --
  157.  # 
  158.  #  Open a help file for the given command, either in Alpha or externally
  159.  #  in Scilab.
  160.  # -------------------------------------------------------------------------
  161.  ##
  162. proc Scil::DblClick {from to shift option control} {
  163.     select $from $to
  164.     set text [getSelect]
  165.     set d "[file join [file dirname [nameFromAppl SLab]] man]"
  166.     set f "[file join ${d} ${text}.hlp]"
  167.     if [file exists $f] {
  168.         global alphaOpensHelpFiles
  169.         if {$alphaOpensHelpFiles} {
  170.             file::openQuietly $f
  171.             changeMode Scil
  172.             global win::Modes
  173.             set "win::Modes($f)" "Scil"
  174.             setWinInfo read-only 1
  175.         } else {
  176.             set name [file tail [app::launchFore SLab]]
  177.             sendOpenEvent noReply $name $f
  178.         }        
  179.     } else {
  180.         alertnote "No such help file exists in Scilab's 'man' directory."
  181.     }
  182. }
  183.  
  184. if [file exists [file join ${PREFS} ScilData]] {
  185.     source [file join ${PREFS} ScilData]
  186. } else {
  187.     alertnote "The first time you use this mode I must build a command database."
  188.     Scil::RebuildElectrics
  189. }
  190. regModeKeywords  -e {//} -c $ScilmodeVars(commentColor) \
  191.     -k $ScilmodeVars(keywordColor)  -s $ScilmodeVars(stringColor) \
  192.     Scil $Scilcmds
  193.